﻿
@{
    ViewData["Title"] = "ModifyBaView";
    Layout = null;
}

<!doctype html>
<html lang="en">
    <link href="~/layer/skin/layer.css" rel="stylesheet"/>
    <link href="~/layui/css/layui.css" rel="stylesheet"/>
<link href="~/bootstrap-3.4.1-dist/css/bootstrap-theme.css" rel="stylesheet"/>
<script src="~/My97DatePicker/WdatePicker.js"></script>
<hr>
<h2 style="margin-left: 200px">基本信息</h2>
<hr>

<form class="layui-form" action="">
    <table>
        <tr>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>姓 名：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="姓名不能为空" id="Name" placeholder="请输入姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>性 别</label>
                    <div>
                        <input type="radio" name="Sex" value="男" title="男" checked>
                        <input type="radio" name="Sex" value="女" title="女">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>手机号：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="手机号不能为空" id="Bphone" placeholder="请输入手机号" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>院 校：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="院校不能为空" id="Bacademy" placeholder="请输入院校" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>专 业：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="专业不能为空" id="Bmajor" placeholder="请输入专业" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>家庭住址：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="家庭住址不能为空" id="Bcolumn" placeholder="请输入家庭住址" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>学 历：</label>
                    <div class="layui-input-block">
                        <select id="Education" lay-verify="">
                            <option value="博士">博士</option>
                            <option value="研究生">研究生</option>
                            <option value="本科">本科</option>
                            <option value="大专">大专</option>
                            <option value="高中">高中</option>
                            <option value="初中">初中</option>
                            <option value="小学">小学</option>
                        </select>  
                    </div>
                </div>
            </td>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">政治面貌：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="政治面貌不能为空" id="Bpolitics" placeholder="请输入政治面貌" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">民 族：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="民族不能为空" id="Bnation" placeholder="请输入民族" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">籍 贯：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="籍贯不能为空" id="Bnative" placeholder="请输入籍贯" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>婚 姻：</label>
                    <div class="layui-input-block">
                        <select id="MaritalStatus" lay-verify="">
                            <option value="未婚">未婚</option>
                            <option value="已婚">已婚</option>
                            <option value="不清楚">不清楚</option>
                        </select>
                    </div>
                </div>
            </td>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">出生年月：</label>
                    <div class="layui-input-block">
                        <input type="text" required class="layui-input" lay-verify="required" id="Bdate" placeholder="请选择出生年月" lay-reqText="出生年月不能为空" autocomplete="off">
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">邮 箱：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="邮箱不能为空" id="Bmailbox" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
            <td style="width: 400px;">
                <div class="layui-form-item">
                    <label class="layui-form-label">身份证号：</label>
                    <div class="layui-input-block">
                        <input type="text" required lay-verify="required" lay-reqText="身份证号不能为空" id="Bnumber" placeholder="请输入身份证号" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <hr class="layui-border-black">
    <h2 style="margin-left: 200px"> 职业信息</h2>
    <hr class="layui-border-black">
    <table>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span> 部  门：</label>
                    <div class="layui-input-block">
                        <select id="Department" name="Department" lay-verify="required" lay-reqText="请选择部门"  lay-filter="Department">
                        </select>
                    </div>
                </div>
            </td>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span> 职  位：</label>
                    <div class="layui-input-block">
                        <select id="Position" name="Position" lay-verify="required"  lay-reqText="请选择职位">
                        </select>
                    </div>
                </div>
            </td>
           
        </tr>
        <tr>
            <td>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">*</span>员工类别：</label>
                    <div class="layui-input-block">
                        <select id="Category" lay-verify="">
                            <option value=" ">全部</option>
                            <option value="正式员工">正式员工</option>
                            <option value="实习生">实习生</option>
                            <option value="试用工">试用工</option>
                        </select>
                    </div>
                </div>
            </td>
        </tr>
    </table>
</form>
<div style="margin-left: 200px">
    <input type="button" class="layui-btn layui-btn-normal" value="保存" onclick="ModifyEmployee()" />
    <input type="button" class="layui-btn layui-btn-primary" value="返回" onclick="location.href='/PersonnelMatters/EmployeeRegistrationView'" />
</div>
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/layer/layer.js"></script>
<script src="~/layui/layui.js"></script>
<script>
    id=@ViewBag.id;
    //反填
    function BackFilling() {
        $.ajax({
            url: "/PersonnelMatters/GetBasicById?id=" + id,
            type: "get",
            success: function(obj) {
                $("#Name").val(obj.name);
                $("[name=Sex][value="+obj.sex+"]").prop("checked", true);
                $("#Bphone").val(obj.bphone);
                $("#Bacademy").val(obj.bacademy);
                $("#Bmajor").val(obj.bmajor);
                $("#Bcolumn").val(obj.bcolumn);
                $("#Education").val(obj.education);
                $("#Bpolitics").val(obj.bpolitics);
                $("#Bnation").val(obj.bnation);
                $("#Bnative").val(obj.bnative);
                $("#MaritalStatus").val(obj.maritalStatus);
                $("#Bdate").val(renderTime(obj.bdate));
                $("#Bmailbox").val(obj.bmailbox);
                $("#Bnumber").val(obj.bnumber);
                GetDeptinfoList();
                $("#Department").val(obj.did);
                form.render('select');
                GetPositionInfoList();
                $("#Position").val(obj.tId);
                form.render('select');
                $("#Category").val(obj.category);
                form.render('select');
            }
        });
    }
    
    //格式化时间
    function renderTime(date) {
        var dateee = new Date(date).toJSON();
        return new Date(+new Date(dateee) + 8 * 3600).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
    }

    //返回
    function Return() {
        window.parent.location.reload();
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }


    layui.use(['form','laydate'],
        function() {
            form = layui.form;
            var laydate = layui.laydate;
            laydate.render({
                elem: '#Bdate' //指定元素
            });
            BackFilling();
            form.on('select(Department)', function(data) {
                GetPositionInfoList();
            });
        });

    //获取部门集合
    function GetDeptinfoList() {
        $.get("/PersonnelMatters/GetDeptinfoList",
            function(res) {
                var str = '<option value="0">请选择一个部门</option>';
                res.forEach(a => {
                    str += (' <option value="' + a.id + '">' + a.name + '</option>');
                });
                $("#Department").append(str);
            });
        GetPositionInfoList();
    }

    //获取职业集合
    function GetPositionInfoList() {
        var id = $("#Department").val();
        $("#Position").empty();
        $.get("/PersonnelMatters/GetPositionInfoList?id=" + id,
            function(res) {
                var str = '<option value="0">请选择一个职位</option>';
                res.forEach(a => {
                    str += (' <option value="' + a.id + '">' + a.name + '</option>');
                });
                $("#Position").append(str);
                form.render('select');
            });
    }


    //修改
    function ModifyEmployee() {
        var data = {
            Id: id,
            Name: $("#Name").val(),
            Sex: $("[name=Sex]:checked").val(),
            Bphone: $("#Bphone").val(),
            Bacademy: $("#Bacademy").val(),
            Bmajor: $("#Bmajor").val(),
            Bcolumn: $("#Bcolumn").val(),
            Education: $("#Education").val(),
            Bpolitics: $("#Bpolitics").val(),
            Bnation: $("#Bnation").val(),
            Bnative: $("#Bnative").val(),
            MaritalStatus: $("#MaritalStatus").val(),
            Bdate: $("#Bdate").val(),
            Bmailbox: $("#Bmailbox").val(),
            Bnumber: $("#Bnumber").val(),
            Did: $("#Department").val(),
            Tid: $("#Position").val(),
            Category: $("#Category").val()
        };
        if (data.Name === "") {
            layer.msg("姓名不能为空");
            return;
        }
        if (data.Sex === "") {
            layer.msg("性别必选");
            return;
        }
        if (data.Bphone === "") {
            layer.msg("手机号不能为空");
            return;
        }
        if (data.Bacademy === "") {
            layer.msg("院校不能为空");
            return;
        }
        if (data.Bmajor === "") {
            layer.msg("专业不能为空");
            return;
        }
        if (data.Bcolumn === "") {
            layer.msg("家庭住址不能为空");
            return;
        }
        if (data.Education === "") {
            layer.msg("学历不能为空");
            return;
        }
        if (data.Did === null) {
            layer.msg("部门不能为空");
            return;
        }
        if (data.Tid === null) {
            layer.msg("职位不能为空");
            return;
        }
        if (data.Category === "") {
            layer.msg("类别不能为空");
            return;
        }
        $.ajax({
            url: "/PersonnelMatters/PostBasic",
            type: "post",
            data: data,
            success: function(obj) {
                if (obj > 0) {
                    layer.alert('修改成功！');
                } else {
                    layer.alert('修改失败');
                }
            }
        });
    }
</script>
</html>

